package com.igoal.dto;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.igoal.entity.ActionTypeEnum;
import com.igoal.entity.ComponentEnum;
import com.igoal.entity.User;
import com.igoal.entity.UserInfo;
import com.igoal.entity.WallUpdate;
import com.igoal.utils.CalendarUtils;
import com.igoal.utils.StringUtils;
import com.igoal.utils.SynchronizeAttributeWithOther;
import com.igoal.utils.SynchronizeDirection;
import com.igoal.web.model.DummySettings;

public class WallActivityDTO extends BaseDTO<WallUpdate> implements Serializable {
	private static final long serialVersionUID = -5739065685939724417L;

	private String componentOwner;
	private String componentOwnerName;
	private String componentOwnerAvatar;
	private String component;
	private String componentId;
	private String componentTitle;
	private String componentLink;
	private String action;
	private String postOwner;
	private String postOwnerName;
	private String postOwnerAvatar;

	private boolean likeEnabled = true;
	private boolean likeThis = false;
	private int likeCount = 0;
	private List<FriendDTO> randomUserLikes;
	private String likeComponent;
	private Long likeComponentId;

	private boolean commentEnabled = true;
	private int commentCount = 0;
	private List<CommentDTO> latestComments;
	private Long lastCommentTime;
	private String commentComponent;
	private Long commentComponentId;

	public String getComponentOwner() {
		return componentOwner;
	}

	public void setComponentOwner(String componentOwner) {
		this.componentOwner = componentOwner;
	}

	public String getComponentOwnerName() {
		return componentOwnerName;
	}

	public void setComponentOwnerName(String componentOwnerName) {
		this.componentOwnerName = componentOwnerName;
	}

	public String getComponentOwnerAvatar() {
		return componentOwnerAvatar;
	}

	public void setComponentOwnerAvatar(String componentOwnerAvatar) {
		this.componentOwnerAvatar = componentOwnerAvatar;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getComponent() {
		return component;
	}

	public void setComponent(String component) {
		this.component = component;
	}

	public String getComponentId() {
		return componentId;
	}

	public void setComponentId(String componentId) {
		this.componentId = componentId;
	}

	public String getComponentTitle() {
		return componentTitle;
	}

	public void setComponentTitle(String componentTitle) {
		this.componentTitle = componentTitle;
	}

	public String getComponentLink() {
		return componentLink;
	}

	public void setComponentLink(String componentLink) {
		this.componentLink = componentLink;
	}

	public boolean isLikeEnabled() {
		return likeEnabled;
	}

	public void setLikeEnabled(boolean likeEnabled) {
		this.likeEnabled = likeEnabled;
	}

	public boolean getLikeThis() {
		return likeThis;
	}

	public void setLikeThis(boolean isLikeThis) {
		this.likeThis = isLikeThis;
	}

	public int getLikeCount() {
		return likeCount;
	}

	public void setLikeCount(int likeCount) {
		this.likeCount = likeCount;
	}

	public List<FriendDTO> getRandomUserLikes() {
		return randomUserLikes;
	}

	public void setRandomUserLikes(List<FriendDTO> randomUserLikes) {
		this.randomUserLikes = randomUserLikes;
	}

	public String getLikeComponent() {
		return likeComponent;
	}

	public void setLikeComponent(String likeComponent) {
		this.likeComponent = likeComponent;
	}

	public Long getLikeComponentId() {
		return likeComponentId;
	}

	public void setLikeComponentId(Long likeComponentId) {
		this.likeComponentId = likeComponentId;
	}

	public boolean isCommentEnabled() {
		return commentEnabled;
	}

	public void setCommentEnabled(boolean commentEnabled) {
		this.commentEnabled = commentEnabled;
	}

	public int getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(int commentCount) {
		this.commentCount = commentCount;
	}

	public List<CommentDTO> getLatestComments() {
		return latestComments;
	}

	public void setLatestComments(List<CommentDTO> latestComments) {
		this.latestComments = latestComments;
	}

	public Long getLastCommentTime() {
		return lastCommentTime;
	}

	public void setLastCommentTime(Long lastCommentTime) {
		this.lastCommentTime = lastCommentTime;
	}

	public String getCommentComponent() {
		return commentComponent;
	}

	public void setCommentComponent(String commentComponent) {
		this.commentComponent = commentComponent;
	}

	public Long getCommentComponentId() {
		return commentComponentId;
	}

	public void setCommentComponentId(Long commentComponentId) {
		this.commentComponentId = commentComponentId;
	}

	public String getPostOwner() {
		return postOwner;
	}

	public void setPostOwner(String postOwner) {
		this.postOwner = postOwner;
	}

	public String getPostOwnerName() {
		return postOwnerName;
	}

	public void setPostOwnerName(String postOwnerName) {
		this.postOwnerName = postOwnerName;
	}

	public String getPostOwnerAvatar() {
		if (StringUtils.isBlank(postOwnerAvatar)) {
			return DummySettings.DEFAULT_AVATAR_URL;
		}
		return postOwnerAvatar;
	}

	public void setPostOwnerAvatar(String postOwnerAvatar) {
		this.postOwnerAvatar = postOwnerAvatar;
	}

	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.FROM, value = "createDate")
	public void initUpdatedSinceFromEntity(Object entity) {
		if (entity != null && entity instanceof Date) {
			Date date = (Date) entity;
			this.updatedSince = CalendarUtils.calculateMinutesDifferentBeforeNow(date);
			this.updateDate = date.getTime();
		}
	}

	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.FROM, value = "component")
	public void initComponentType(Object entity) {
		if (entity != null && entity instanceof ComponentEnum) {
			ComponentEnum componentType = ComponentEnum.valueOf(entity.toString());
			component = componentType.toString();
		}
	}

	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.FROM, value = "componentOwner")
	public void initComponentOwnerName(Object entity) {
		if (entity != null && entity instanceof User) {
			User user = (User) entity;
			componentOwner = user.getUsername();
			componentOwnerAvatar = user.getAvatar();
			if (StringUtils.isBlank(componentOwnerAvatar)) {
				componentOwnerAvatar = DummySettings.DEFAULT_AVATAR_URL;
			}

			UserInfo info = user.getUserInfo();
			String firstName = info.getFirstName();
			String midleName = info.getMiddleName();
			String lastName = info.getLastName();

			componentOwnerName = StringUtils.buildDisplayName(componentOwner, firstName, midleName,
					lastName);
		}
	}

	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.FROM, value = "action")
	public void initActionType(Object entity) {
		if (entity != null && entity instanceof ActionTypeEnum) {
			ActionTypeEnum actionType = ActionTypeEnum.valueOf(entity.toString());
			action = actionType.toString();
		}
	}

}
